package com.itjin.controller;

import com.itjin.model.domain.vo.AnxietyTipsVO;
import com.itjin.model.domain.vo.ExamHelperVO;
import com.itjin.model.domain.vo.PredictedPointVO;
import com.itjin.model.domain.vo.StudyPlanVO;
import com.itjin.model.request.StudyPlanRequest;
import com.itjin.model.request.WrongQuestionRequest;
import com.itjin.model.result.Result;
import com.itjin.service.ExamHelperService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
 * 智能考试助手控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/exam-helpers")
@Tag(name = "智能考试助手接口")
@Validated
public class ExamHelperController {

  @Autowired
  private ExamHelperService examHelperService;

  /**
   * 获取用户所有考试助手信息
   */
  @GetMapping
  @Operation(summary = "获取用户所有考试助手信息")
  public Result<List<ExamHelperVO>> getUserExamHelpers(@RequestParam Integer userId) {
    log.info("获取用户考试助手信息，userId:{}", userId);
    return Result.success(examHelperService.getUserExamHelpers(userId));
  }

  /**
   * 创建或更新复习计划
   */
  @PostMapping("/study-plans")
  @Operation(summary = "创建或更新复习计划")
  public Result<StudyPlanVO> createStudyPlan(
      @RequestParam Integer userId,
      @RequestBody @Valid StudyPlanRequest request) {
    log.info("创建复习计划，userId:{}, courseId:{}", userId, request.getCourseId());
    return Result.success(examHelperService.createStudyPlan(userId, request));
  }

  /**
   * 获取预测考点
   */
  @GetMapping("/predicted-points/{courseId}")
  @Operation(summary = "获取预测考点")
  public Result<PredictedPointVO> getPredictedPoints(
      @RequestParam Integer userId,
      @PathVariable Integer courseId) {
    log.info("获取预测考点，userId:{}, courseId:{}", userId, courseId);
    return Result.success(examHelperService.getPredictedPoints(userId, courseId));
  }

  /**
   * 添加错题记录
   */
  @PostMapping("/wrong-questions")
  @Operation(summary = "添加错题记录")
  public Result<Boolean> addWrongQuestion(
      @RequestParam Integer userId,
      @RequestBody @Valid WrongQuestionRequest request) {
    log.info("添加错题记录，userId:{}, courseId:{}", userId, request.getCourseId());
    return Result.success(examHelperService.addWrongQuestion(userId, request));
  }

  /**
   * 获取考前焦虑缓解建议
   */
  @GetMapping("/anxiety-tips")
  @Operation(summary = "获取考前焦虑缓解建议")
  public Result<AnxietyTipsVO> getAnxietyTips(
      @RequestParam Integer userId,
      @RequestParam Integer courseId) {
    log.info("获取考前焦虑缓解建议，userId:{}, courseId:{}", userId, courseId);
    return Result.success(examHelperService.getAnxietyTips(userId, courseId));
  }

  /**
   * 更新学习进度
   */
  @PutMapping("/progress")
  @Operation(summary = "更新学习进度")
  public Result<Boolean> updateStudyProgress(
      @RequestParam Integer userId,
      @RequestParam Integer courseId,
      @RequestParam Integer progress) {
    log.info("更新学习进度，userId:{}, courseId:{}, progress:{}", userId, courseId, progress);
    return Result.success(examHelperService.updateStudyProgress(userId, courseId, progress));
  }
}